home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / SAMPLES1.PAK / WINAPI.WFM < prev   
Text File  |  1995-07-18  |  16KB  |  444 lines

  1. *****************************************************************************
  2. *  PROGRAM:      WinApi.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         6/28/93
  7. *
  8. *  UPDATED:      5/95
  9. *
  10. *  REVISION      $Revision:   1.57  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This program shows how to access useful Windows API functions
  15. *                using the Visual dBASE API interface.
  16. *                A form is displayed with pushbuttons containing different
  17. *                information that can be accessed with the Windows API through
  18. *                Visual dBASE.  Pressing a pushbutton executes the selected
  19. *                function (or series of functions).  The Close pushbutton
  20. *                closes the window.
  21. *
  22. *  PARAMETERS:   None
  23. *
  24. *  CALLS:        Buttons.cc       (Custom controls file)
  25. *                SysInfo.wfm      (Form for displaying system information)
  26. *
  27. *                GetWinFlags()    (Windows API functions)
  28. *                GetModuleUsage()
  29. *                GetModuleHandle()
  30. *                GetVersion()
  31. *                ShowWindow()
  32. *                GetFreeSpace()
  33. *                SystemParametersInfo()
  34. *                MessageBox()
  35. *                GetWindowText()
  36. *                CloseWindow()
  37. *                OpenIcon()
  38. *                GetWindowsDirectory()
  39. *                GetPrivateProfileString()
  40. *
  41. *  USAGE:        DO Winapi.wfm
  42. *
  43. *
  44. *
  45. *******************************************************************************
  46. #include <Messdlg.h>
  47. #include <Winapi.h>
  48.  
  49. #define  ENTER    chr(13)
  50. #define  TAB      chr(9)
  51.  
  52. create session
  53. set talk off
  54. set ldCheck off
  55.  
  56. ** END HEADER -- do not remove this line*
  57. * Generated on 07/11/95
  58. *
  59. parameter bModal
  60. local f
  61. f = new WINAPIFORM()
  62. if (bModal)
  63.    f.mdi = .F. && ensure not MDI
  64.    f.ReadModal()
  65. else
  66.    f.Open()
  67. endif
  68. CLASS WINAPIFORM OF FORM
  69.    Set Procedure To &_dbwinhome.samples\BUTTONS.CC additive
  70.    this.OnOpen = CLASS::ONOPEN
  71.    this.Width = 42.666
  72.    this.OnClose = CLASS::ONCLOSE
  73.    this.Top = 0.9404
  74.    this.MousePointer = 1
  75.    this.Left = 33.666
  76.    this.ColorNormal = "BTNTEXT/BTNFACE"
  77.    this.Text = "Windows API Call Demo"
  78.    this.Height = 14.2939
  79.    this.Maximize = .F.
  80.    this.Minimize = .F.
  81.  
  82.    DEFINE RECTANGLE RECTANGLE1 OF THIS;
  83.        PROPERTY; 
  84.          Width 25.6816,;
  85.          Top 0.5391,;
  86.          Left 1.3184,;
  87.          Text "",;
  88.          Height 13.7549
  89.  
  90.    DEFINE PUSHBUTTON SYSINFOBUTTON OF THIS;
  91.        PROPERTY; 
  92.          Width 23.8535,;
  93.          Group .T.,;
  94.          StatusMessage "Show information about the system.",;
  95.          FontSize 6,;
  96.          Top 1.0596,;
  97.          Left 1.9795,;
  98.          Text "System Information",;
  99.          Height 1.5869,;
  100.          OnClick CLASS::SYSINFO,;
  101.          Default .T.
  102.  
  103.    DEFINE PUSHBUTTON OKCANBOXBUTTON OF THIS;
  104.        PROPERTY; 
  105.          Width 23.8535,;
  106.          Group .F.,;
  107.          StatusMessage "Show a message dialog.",;
  108.          Top 2.918,;
  109.          Left 1.9795,;
  110.          Text "   Message Box    ",;
  111.          Height 1.6113,;
  112.          OnClick CLASS::OKCANBOX
  113.  
  114.    DEFINE PUSHBUTTON WINWALLPAPERBUTTON OF THIS;
  115.        PROPERTY; 
  116.          Width 23.8535,;
  117.          Group .F.,;
  118.          StatusMessage "Show how the wallpaper can be changed from Visual dBASE.",;
  119.          Top 4.7793,;
  120.          Left 1.9795,;
  121.          Text "    Wallpaper     ",;
  122.          Height 1.5732,;
  123.          OnClick CLASS::WINWALLPAPER
  124.  
  125.    DEFINE PUSHBUTTON WINDOWCAPTIONSBUTTON OF THIS;
  126.        PROPERTY; 
  127.          Width 23.8535,;
  128.          Group .F.,;
  129.          StatusMessage "Show the caption of the Visual dBASE frame retrieved from the Api and dBASEWIN.",;
  130.          Top 6.6299,;
  131.          Left 1.9795,;
  132.          Text " Window Captions  ",;
  133.          Height 1.6045,;
  134.          OnClick CLASS::WINDOWCAPTIONS
  135.  
  136.    DEFINE PUSHBUTTON WINDIRECTORYBUTTON OF THIS;
  137.        PROPERTY; 
  138.          Width 23.8535,;
  139.          Group .F.,;
  140.          StatusMessage "Show the Windows home directory.",;
  141.          Top 8.4795,;
  142.          Left 1.9795,;
  143.          Text "Windows Directory ",;
  144.          Height 1.5791,;
  145.          OnClick CLASS::WINDIRECTORY
  146.  
  147.    DEFINE PUSHBUTTON DBWINICONBUTTON OF THIS;
  148.        PROPERTY; 
  149.          Width 23.8535,;
  150.          Group .F.,;
  151.          StatusMessage "Make Visual dBASE minimized for a short time.",;
  152.          Top 10.3389,;
  153.          Left 1.9795,;
  154.          Text "Icon",;
  155.          Height 1.6016,;
  156.          OnClick CLASS::ICONIZE
  157.  
  158.    DEFINE PUSHBUTTON WHOAMIBUTTON OF THIS;
  159.        PROPERTY; 
  160.          Width 23.8535,;
  161.          Group .F.,;
  162.          StatusMessage "Display information about the user.",;
  163.          Top 12.1973,;
  164.          Left 1.9795,;
  165.          Text "Who Am I?",;
  166.          Height 1.5674,;
  167.          OnClick CLASS::WHOAMI
  168.  
  169.    DEFINE CLOSEBUTTON CLOSEWINAPIBUTTON OF THIS;
  170.        PROPERTY; 
  171.          Width 14.1201,;
  172.          Group .T.,;
  173.          StatusMessage "Leave Winapi.",;
  174.          Top 1.0596,;
  175.          Left 28.3799,;
  176.          Height 1.5283
  177.  
  178.    DEFINE SAMPLEINFOBUTTON WINAPIINFOBUTTON OF THIS;
  179.        PROPERTY; 
  180.          Width 3.5,;
  181.          Group .T.,;
  182.          Top 13,;
  183.          Left 39,;
  184.          Text "",;
  185.          Height 1.1758
  186.  
  187.    procedure OnOpen
  188.    *******************************************************************************
  189.    
  190.    set procedure to &_dbwinhome.samples\Sampproc.prg additive
  191.    this.winapiInfoButton.sampleName = "Winapi.wfm"
  192.    
  193.    
  194.    *******************************************************************************
  195.    
  196.    procedure OnClose
  197.    *******************************************************************************
  198.    
  199.    close procedure &_dbwinhome.samples\Buttons.cc,;
  200.       &_dbwinhome.samples\Sampproc.prg
  201.    
  202.    
  203.    *******************************************************************************
  204.    
  205.    procedure SysInfo
  206.    
  207.    * Bring up form with various system information.
  208.    *******************************************************************************
  209.    local info
  210.    
  211.    _app.framewin.visible = .F.                  && if frame invisible at that time
  212.    set procedure to &_dbwinhome.samples\Sysinfo.wfm additive
  213.    info = new SysInfoForm()
  214.    info.Readmodal()
  215.    form.visible = .T.
  216.    _app.framewin.visible = .T.
  217.    close procedure &_dbwinhome.samples\Sysinfo.wfm
  218.    
  219.    
  220.    *******************************************************************************
  221.    
  222.    function OkCanBox(cMess, cTitle)
  223.    
  224.    * OkCanBox(<cMess>,<cTitle>).
  225.    * <cMess>  = Message to display in Box.
  226.    * <cTitle> = Title of Message Box.
  227.    *
  228.    * Creates a MessageBox on the SCREEN with
  229.    * a title and message text. The user must
  230.    * press or click OK or CANCEL or press ESCAPE
  231.    * key. This is a System Modal MessageBox.
  232.    * Calls the User.exe function MessageBox()
  233.    * -- the Borland version of the Windows function MessageBox().
  234.    * choice = okcanbox("Read my lips","Message Box")
  235.    * 2 if Escape pressed, 1 if OK button pressed,
  236.    * 2 if CANCEL pressed. Or 0 if not enough memory.
  237.    *******************************************************************************
  238.    * Returns 0 if not enough memory to create MessageBox.
  239.    * Returns 1=OK,2=CANCEL,3=ABORT,4=RETRY,5=IGNORE,6=YES,7=NO,8=ONE
  240.    *   wType any combo of below
  241.    *       MODE                         DEFAULT BUTTON
  242.    *0x3000h=12288D Mode Mask  0x0F00h=3840 Dec Def.Button
  243.    *0x0000h=00000D App Modal  0x0000h=0000 Dec Button 1
  244.    *0x1000h=04096D Sys Modal  0x0100h=0256 Dec Button 2
  245.    *0x2000h=08192D Task Modal 0x0200h=0512 Dec Button 3
  246.    *                          0x0300h=0768 Dec Button 4
  247.    *                          0x0400h=1024 Dec Button 5
  248.    *                          0x0500h=1280 Dec Button 6
  249.    *                          0x0600h=1536 Dec Button 7
  250.    *                          0x0700h=1792 Dec Button 8
  251.    *        ICON                           BUTTON
  252.    *0x00F0h=0240D Icon Mask  0x000Fh=0015Dec Type Mask
  253.    *0x0010h=0016D Hand       0x0000h=0000Dec OK Button
  254.    *0x0010h=0016D Stop *     0.00x0001h=0001Dec OK CANCEL
  255.    *0x0020h=0032D Question   0x0002h=0002Dec ABORT RETRY IGNORE
  256.    *0x0030h=0048D Exclaimation 0003h=0003Dec YES NO CANCEL
  257.    *0x0040h=0064D Astrisk    0x0004h=0004Dec YES NO
  258.    *0x0040h=0064D Information x0005h=0005Dec RETRY CANCEL
  259.    *                         0x0008h=0008Dec ABORT RETRY
  260.    *                         0x0009h=0009Dec OK CANCEL ABORT
  261.    *                                         RETRY IGNORE
  262.    *                         0x000Ah=0010Dec NO CANCEL RETRY
  263.    *                                         CANCEL GARBAGE
  264.    *                         0x000Bh=0011Dec OK CANCEL ABORT
  265.    *                                         RETRY IGNORE YES
  266.    *                                         NO CANCEL
  267.    *******************************************************************************
  268.    private cMess1, cTitle1, value
  269.    
  270.    cMess1 = iif(empty(cMess),;
  271.                 FormatStr("Put Message Here! \n" +;
  272.                           "Syntax is: \n" +;
  273.                           "? OkCanBox('Message','Title') \n\n" +;
  274.                           "Returns: \n" +;
  275.                           "1 if OK button clicked or pressed \n" +;
  276.                           "2 if Cancel button or Escape key pressed \n" +;
  277.                           "0 if not enough memory to run"),;
  278.                 cMess)
  279.    
  280.    cTitle1 = iif(empty(cTitle),"OkCanBox( ) Message Function",cTitle)
  281.    value = MessageBox(0,;
  282.                       ansi(cMess1),;
  283.                       ansi(cTitle1),;
  284.                       INFORMATION_MESSAGE + OK_CANCEL_BUTTONS)
  285.    ?value
  286.    
  287.    return value
  288.    
  289.    
  290.    
  291.    *******************************************************************************
  292.    
  293.    procedure WinWallpaper
  294.    
  295.    * Calls the Windows WallPaper changer program.
  296.    * First it reduces Visual dBASE to an icon, then it
  297.    * changes into the Windows directory and displays a
  298.    * GETFILE() box of the *.BMP files in the Windows
  299.    * directory then it changes the desktop wallpaper to
  300.    * the file you choose.Next it asks if you want to keep
  301.    * the Wallpaper or set it to (None) Then it returns to
  302.    * the directory you started from and restores Visual dBASE
  303.    * from the icon.
  304.    *******************************************************************************
  305.    
  306.    * extern CLOGICAL SystemParametersInfo (CINT, CINT, CPTR, CINT) USER
  307.    * extern CVOID    CloseWindow(CHANDLE) USER
  308.    private wallpaper,newWall,orgDir,winPath,changeWallStr
  309.    
  310.    _app.framewin.visible = .F.
  311.    orgDir = set("directory")
  312.    winPath = CLASS::winDirectory(.T.)
  313.    cd &winPath
  314.    wallpaper = getfile("*.BMP","Select New Wallpaper")
  315.    cd &orgDir
  316.    
  317.    changeWallStr = FormatStr("Press OK to change the Wallpaper \n;
  318.    or press Cancel to keep your original wallpaper")
  319.    
  320.    if .not. empty(wallpaper) .and. CLASS::OkCanBox(changeWallStr) = OK
  321.          SystemParametersInfo(20,0,ansi(wallpaper),1)
  322.    endif
  323.    _app.framewin.visible = .T.
  324.    this.SetFocus()
  325.    
  326.    
  327.    
  328.    *******************************************************************************
  329.    
  330.    procedure WindowCaptions
  331.    
  332.    * Calls the Windows function GetFormText to get title of the
  333.    * Visual dBASE frame window
  334.    *******************************************************************************
  335.    * extern CINT GetWindowText (CHANDLE, CSTRING, CINT) USER
  336.    local winTitle,lenTitle,apiStr,objectStr
  337.    
  338.    winTitle = space(80)      && first make empty string to be filled
  339.    lenTitle = GetWindowText(_app.framewin.hwnd,winTitle,80)
  340.    apiStr    = FormatStr("From API call:\t %1", oem(winTitle))
  341.    objectStr = FormatStr("From Visual dBASE:\t %1", (_app.framewin.text))
  342.    MessageBox(0,;
  343.               ansi(apiStr + ENTER + objectStr),;
  344.               ansi("Title of Visual dBASE"),;
  345.               INFORMATION_MESSAGE + OK_BUTTON)
  346.    
  347.    
  348.    
  349.    *******************************************************************************
  350.    
  351.    procedure Iconize
  352.    
  353.    * This example just minimizes Visual dBASE to a
  354.    * ICON (by way of the CloseWindow funtion) waits 5
  355.    * seconds then restores Visual dBASE from its icon.
  356.    *
  357.    *******************************************************************************
  358.    * extern CWORD CloseWindow(CWORD) USER
  359.    * extern CWORD OpenIcon(CWORD) USER
  360.    local frameState
  361.    
  362.    if messageBox(0,;
  363.                  ansi("This will minimize Visual dBASE for 5 seconds. Proceed?"),;
  364.                  ansi("Confirmation"),;
  365.                  CONFIRMATION_MESSAGE + YES_NO_BUTTONS) = YES
  366.       frameState = _app.framewin.windowState + 1  && Save previous frame state
  367.       CloseWindow(_app.framewin.hwnd)             && Reduce Visual dBASE to icon
  368.       inkey(5)                                    && Wait 5 seconds
  369.       ShowWindow(_app.framewin.hwnd,frameState)   && Restore Visual dBASE
  370.                                                   && from an icon
  371.    endif
  372.    
  373.    
  374.    *******************************************************************************
  375.    
  376.    function WinDirectory(dontShowBox)
  377.    
  378.    * Calls the Windows Funnction GetWindowsDirectory( ) which
  379.    * is used to get the Directory that Windows is
  380.    * installed in.
  381.    *
  382.    *******************************************************************************
  383.    * extern CWORD GetWindowsDirectory(CSTRING, CWORD) KERNEL
  384.    local cWinDir
  385.    
  386.    cWinDir = space(144)
  387.    GetWindowsDirectory(cWinDir,144)
  388.    if .not. dontShowBox
  389.       MessageBox(0,;
  390.                  cWinDir,;
  391.                  ansi("Windows Directory"),;
  392.                  INFORMATION_MESSAGE + OK_BUTTON)
  393.    endif
  394.    return oem(cWinDir)
  395.    
  396.    
  397.    *******************************************************************************
  398.    
  399.    procedure WhoAmI
  400.    
  401.    * Displays Windows and Visual dBASE registration information.
  402.    *******************************************************************************
  403.    * extern CWORD GetPrivateProfileString;
  404.    *                            (CSTRING, CPTR, CPTR, CPTR, CWORD, CPTR) KERNEL
  405.    * extern CWORD MessageBox (CWORD, CPTR, CPTR, CWORD) USER
  406.    
  407.    local cUser, cComp, nUserLen, nOrgLen, cIniDir, cWinUsr, cWinComp,;
  408.             nWinUsr, nWinComp
  409.    
  410.    cWinUsr = rtrim( oem(Resource( 514, "USER.EXE" )) )
  411.    cWinComp = rtrim( oem(Resource( 515, "USER.EXE" )) )
  412.    cUser   = space( 50 )
  413.    cComp    = space( 50 )
  414.    cIniDir = _dbwinhome + "BIN\DBASEWIN.INI"
  415.    nUserLen   = GetPrivateProfileString( "Install","Username",'Unknown',cUser,50,;
  416.                                          cIniDir)
  417.    nCompLen    = GetPrivateProfileString( "Install","Company",'Unknown', cComp,50,;
  418.                                          cIniDir)
  419.    nWinUsr = len( cWinUsr )
  420.    nWinComp = len( cWinComp )
  421.    
  422.    cUser   = iif( nUserLen = 0, 'Unknown', left( oem(cUser), nUserLen ) )
  423.    cComp   = iif( nCompLen = 0, 'Unknown', left( oem(cComp), nCompLen ) )
  424.    cWinUsr = iif( nWinUsr = 0, 'Unknown', cWinUsr )
  425.    cWinComp = iif( nWinComp = 0, 'Unknown', cWinComp )
  426.    
  427.    MessageBox(0,;                                             && Display window
  428.               ansi(FormatStr("Visual dBASE Registered to:\n"+ ;  && Message
  429.                              "   Customer Name: \t %1 \n"   + ;
  430.                              "   User Company:  \t %2 \n\n" + ;
  431.                              "Windows Registered to:\n"     + ;
  432.                              "   Customer Name: \t %3 \n"   + ;
  433.                              "   User Company:  \t %4",       ;
  434.                    cUser, cComp, cWinUsr, cWinComp)),         ;
  435.               ansi("Visual dBASE User Information"),          ;  && Title
  436.               INFORMATION_MESSAGE + OK_BUTTON)                   && Window Style
  437.    
  438.    
  439. ENDCLASS
  440.  
  441.  
  442.  
  443.  
  444.